﻿// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

using Microsoft.Extensions.Logging;
using Microsoft.Quantum.Chemistry;
using System.Linq;

// This loads a Hamiltonian from file and computes some of its features
// - L1-Norm of terms

namespace Microsoft.Quantum.Chemistry.Sample
{

    class Program
    {

        static void Main(string[] args)
        {
            var logger = Logging.LoggerFactory.CreateLogger<Program>();

            // Directory containing integral data generated by Microsoft.
            //Example Liquid data format files
            /*
            "h2_sto3g_4.dat" // 4 SO
            "B_sto6g.dat" // 10 SO
            "Be_sto6g_10.dat" // 10 SO
            "h2o_sto6g_14.dat" // 14 SO
            "h2s_sto6g_22.dat" // 22 SO
            "co2_sto3g_30.dat" // 30 SO
            "co2_p321_54.dat" // 54 SO
            "fe2s2_sto3g.dat" // 110 SO
            "nitrogenase_tzvp_54.dat" // 108 SO
            */

            string LiquidRoot = @"..\IntegralData\Liquid\";
            string LiquidFilename = "fe2s2_sto3g.dat";
            // Number of electrons. This must be specified for the liquid format.
            var LiquidElectrons = 2;

            // For loading data in the format consumed by Liquid.
            logger.LogInformation($"Processing {LiquidFilename}");
            var generalHamiltonian = FermionHamiltonian.LoadFromLiquid($@"{LiquidRoot}\{LiquidFilename}").Single();
            generalHamiltonian.NElectrons = LiquidElectrons;

            // For loading data in the YAML format.
            //string YAMLRoot = @"..\IntegralData\YAML\";
            //string YAMLFilename = "lih_sto-3g_0.800_int.yaml";
            //var generalHamiltonian = FermionHamiltonian.LoadFromYAML($@"{YAMLRoot}\{YAMLFilename}").Single();

            // Read Hamiltonian terms from file.

            logger.LogInformation("End read file. Computing one-norms.");
            foreach (var oneNormPair in generalHamiltonian.ComputeOneNorms())
            {
                logger.LogInformation($"One-norm for term type {oneNormPair.Key}: {oneNormPair.Value}");
            }
            logger.LogInformation("Computed one-norm.");

            if (System.Diagnostics.Debugger.IsAttached)
            {
                System.Console.ReadLine();
            }
        }
    }
}

